import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';

class FocusUtils {
  FocusUtils._();

  static void unFocus() {
    try {
      FocusScopeNode currentFocus = FocusScope.of(Get.context!);
      if (currentFocus.focusedChild != null && !currentFocus.hasPrimaryFocus) {
        FocusManager.instance.primaryFocus?.unfocus();
      } else {
        SystemChannels.textInput.invokeMethod('TextInput.hide');
      }
    } catch (e) {}
  }
}
